import { User, UserProfile } from '@/types/data'
import { ProfileAction } from '@/types/store'

// 当前Reducer不止保存用户相关信息
type ProfileState = {
  user: User
  userProfile: UserProfile
}

// 初始状态
const initialValue: ProfileState = {
  user: {},
  userProfile: {}
} as ProfileState

export default function ProfileReducer(
  state = initialValue,
  action: ProfileAction
) {
  if (action.type === 'profile/set_user') {
    return {
      ...state,
      user: action.payload
    }
  }
  if (action.type === 'profile/set_user_profile') {
    return {
      ...state,
      userProfile: action.payload
    }
  }
  return state
}
